/**
 * 封装 axios 请求模块
 */
import axios from 'axios'
import jsonBig from 'json-bigint'
import store from '@/store'
const request = axios.create({
  baseURL: 'http://toutiao-app.itheima.net/', // 基础路径
  transformResponse: [
    function(data) {
      try {
        return jsonBig.parse(data)
      } catch (err) {
        return data
      }
    }
  ]
})
// 设置请求头
request.interceptors.request.use(config => {
  const { user } = store.state
  if (user && user.token) {
    config.headers.Authorization = `Bearer ${user.token}`
  }
  return config
})
export default request
